package com.zyw.zhuangdian.controller;

import com.zyw.zhuangdian.enums.MsgCode;
import com.zyw.zhuangdian.pojo.Resp;
import com.zyw.zhuangdian.util.RespUtil;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class ErrorController implements org.springframework.boot.web.servlet.error.ErrorController {

    @RequestMapping("/error")
    public ResponseEntity<Resp<?>> handleError(@RequestParam(value = "error",required = false,defaultValue = "404") String error){
        if (error!=null ){
            if (error.equals("401")){
                return RespUtil.UN_AUTH(new Resp<>(MsgCode.MSG_UN_AUTH));
            }
        }
        return RespUtil.NOT_FOUND(new Resp<>(MsgCode.MSG_NOT_FOUND));
    }

    public String getErrorPath() {
        return "/error";
    }
}
